home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
loading
/
testload.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-04-03
|
4KB
|
169 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA
endcopyright */
#include <stdio.h>
#include <string.h>
#include <sys/file.h>
#include <sys/types.h>
#include <setjmp.h>
#include <xr/unwind.h>
struct LDGLOBAL ldglobal_real, *ldglobal = &ldglobal_real;
extern char **environ;
static char sep[] = " \t\n";
extern char *sprintf();
char f_name[128];
extern char **XR_argv;
XR_StartMainXR()
{
int ret;
FILE *dbxinitfile;
int dbxinitfiledes, pid;
char name[128];
char *current;
char cmd[1024];
char func_name[128];
Installer_Func load_file(), installval;
LDGLOBAL_loader_print = 1;
init_dyload(XR_argv[0], 0, 0);
/* drop a XrshDBX into the local world to start a debugger. */
get_dyload_filename(name, "");
pid = getpid();
dbxinitfiledes = open("XrshDBX", O_CREAT | O_WRONLY, 0777);
dbxinitfile = fdopen(dbxinitfiledes, "w");
fprintf(dbxinitfile, "#!/bin/csh -f\n");
fprintf(dbxinitfile, "cp %s %s.dbx\n", name, name);
fprintf(dbxinitfile, "transform_symtab %s.dbx\n", name);
fprintf(dbxinitfile, "exec dbx -I. %s.dbx %d\n", name, pid);
fclose(dbxinitfile);
printf("'XrshDBX' command installed in current directory.\n");
while (!feof(stdin)) {
printf("Enter command: ");
if (gets(cmd) == NULL)
break;
if (! isatty(fileno(stdin))) {
/* echo command if not reading from a tty */
printf("%s\n", cmd);
}
current = strtok(cmd, sep);
if (current == 0) current = "";
switch (current[0]) {
case '?': case '\0': {
printcmds();
break;
}
case 's': {
int secs;
if ((current = strtok(NULL, sep)) == NULL) {
printcmds();
break;
}
secs = atol(current);
printf("Sleeping %d seconds.\n", secs);
sleep(secs);
break;
}
case 'l': {
if ((current = strtok(NULL, sep)) == NULL) {
printcmds();
break;
}
strcpy(f_name, current);
time_load();
break;
}
case 'c': {
int (*func)(), (*complete_get_sym_val())(), (*get_sym_val())();
if ((current = strtok(NULL, sep)) == NULL) {
printcmds();
break;
}
if ((func = get_sym_val(current)) == NULL) {
printf("Couldn't find function '%s' to call.\n", current);
} else {
printf("'%s' returns %x\n", current, (*func)(current));
}
break;
}
case 'd': {
char name[128];
char num[128];
int pid;
get_dyload_filename(name, "");
pid = getpid();
if (! fork()) {
/* run debugger in a child */
int fd;
/* close weird fd's (kludge!) */
for (fd=3; fd < 20; fd++)
(void) close(fd);
sprintf(num, "%d", pid);
execle("/usr/bin/dbxtool", "dbxtool", name, num, 0, environ);
/* Should not get here */
printf("Execve failed.\n");
abort();
}
break;
}
case 'q': {
goto leaveloop;
break;
}
} /* end of switch */
} /* end of while */
leaveloop:
{
char name[128];
get_dyload_filename(name, "");
unlink(name);
strcat(name, ".dbx");
unlink(name);
}
printf("\nNormal termination.\n");
}
dumphex(s, len)
char *s;
{
for (; len > 0; len--) {
printf(" %2x", 0xff & *s);
s += 1;
}
printf("\n");
}
printcmds()
{
printf("Commands are:\nload file\ndebug\nsleep secs\ncall _funcname\nquit\nprint\n");
}
noarg_load()
{
load_file(f_name, NULL, 1, 0);
}
time_load()
{
time_func_call_with_children(noarg_load, 1);
}